package com.example.zy5_project_jetpack.mvp.view.Activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.zy5_project_jetpack.R;
import com.example.zy5_project_jetpack.mvp.view.FindFragment.FindFragment;
import com.example.zy5_project_jetpack.mvp.view.Fragment.AddFragment;
import com.example.zy5_project_jetpack.mvp.view.Fragment.HomeFragment;
import com.example.zy5_project_jetpack.mvp.view.Fragment.MyFragment;
import com.example.zy5_project_jetpack.mvp.view.SofaFragment.SofaFragment;
import com.example.zy5_project_jetpack.mvp.view.FragmentAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ViewPager view_pager;
    private TabLayout tab_main;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        initView();
//        initFragment();
    }

    private void initFragment() {


    }

    private void initView() {
        view_pager = (ViewPager) findViewById(R.id.view_pager);
        tab_main = (TabLayout) findViewById(R.id.tab_main);


        final ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new SofaFragment());
        fragments.add(new AddFragment());
        fragments.add(new FindFragment());
        fragments.add(new MyFragment());
        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
        view_pager.setAdapter(fragmentAdapter);

        tab_main.setupWithViewPager(view_pager);
        tab_main.getTabAt(0).setText("首页").setIcon(R.drawable.home_image_tab);
        tab_main.getTabAt(1).setText("沙发").setIcon(R.drawable.sofa_image_tab);
        tab_main.getTabAt(2).setText("").setIcon(R.drawable.icon_tab_publish);
        tab_main.getTabAt(3).setText("发现").setIcon(R.drawable.find_image_tab);
        tab_main.getTabAt(4).setText("我的").setIcon(R.drawable.my_image_tab);
    }
}
